<template>
	<view class="content">
		<view class="block classify-tab-block">
			<view class="tab-content">
				<view class="tab-item" :class="tabActive==1?'active':''" @click="bindActive(1)">推荐{{pageType}}</view>
				<view class="tab-item" :class="tabActive==2?'active':''" @click="bindActive(2)" v-if="identity==1">推荐招聘会
				</view>
				<view class="tab-item" :class="tabActive==3?'active':''" @click="bindActive(3)" v-if="identity==1">推荐培训
				</view>
			</view>
		</view>
		<block v-if="tabActive==1">
			<template v-if="list.length>0">
				<view v-if="identity==1&&tabActive==1" class="block list-block">
					<view
						@click="navigate('/page_other/job_hunting/job_detail/index?id='+item.id+'&jobType='+item.jobType)"
						class="list-item" v-for="(item,index) in list" :key="item.id">
						<view style="display: flex;">
							<view class="list-info">
								<view class="title-info">
									<view class="title">{{item.jobTitle}}</view>
									<view class="fast-job" v-if="item.worry">急招</view>
									<view v-if="item.isHeat">
										<image style="width: 21px;height: 25px;padding-top: 10rpx;"
											:src="cloudStorage+'home/heat.png'">
										</image>
									</view>
								</view>
								<view class="wage" v-if="item.minSalary">{{item.minSalary}}-{{item.maxSalary}}<text
										class="unit">元</text></view>
								<view class="wage" v-else>面议</view>
								<view class="label-block">
									<view class="label-item" v-for="label in item.label">{{label}}</view>
								</view>
								<view class="address iconfont icon-dizhi">{{item.jobAddress}}</view>
							</view>
							<view class="detail-info">
								<view class="name">{{item.comRecruiters.comPosition}}</view>
								<image mode="aspectFill" :src="item.comRecruiters.user.faceUrl" class="photo"></image>
								<view class="distance">距离:{{item.distances}}km</view>
							</view>
						</view>
						<view class="com-item">
							<image mode="aspectFill" :src="item.comRecruiters.enterprise.logoUrl" class="photo">
							</image>
							<view class="distance">{{item.comRecruiters.enterprise.enterpriseName}}</view>
						</view>
					</view>
				</view>
				<view v-if="identity==2" class="block list-block">
					<CustomerList :key="item.id" :data="item" v-for="(item) in list"></CustomerList>
				</view>
			</template>
			<view v-else-if="list.length>0&&!more" style="text-align: center;">到底了</view>
			<view v-else style="text-align: center;">暂未匹配到相关{{pageType}}</view>
		</block>
		<block v-if="identity==1&&tabActive==2">
			<template v-if="FairList.length>0">
				<view class="block list-block">
					<view class="model" v-for="(item,index) in FairList" :key="item.id">
						<view v-if="item.state==1" class="ranking-block">预定中</view>
						<view v-if="item.state==2" class="ranking"></view>
						<view v-if="item.state==3" class="ranking-blockgrey">已结束</view>
						<view class="list-item">
							<image mode="aspectFill" :src="item.coverUrl" class="cover-photo"></image>
							<view class="info">
								<view class="title">{{item.title}}</view>
								<view class="incount">
									<view class="module">企业{{item.qyCount}}家</view>
									<view class="module">职位{{item.zwCount}}个</view>
								</view>
							</view>
						</view>
						<view class="lower">
							<view class="time">{{item.eventTimeStart}}
							</view>
							<view @click="navigate('/page_other/job_hunting/job_fair/detail?id='+item.id)" class="btn">
								进入会场
							</view>
						</view>
					</view>
				</view>
			</template>
			<view v-else-if="FairList.length>0&&!more" style="text-align: center;">到底了</view>
			<view v-else style="text-align: center;">暂未匹配到相关招聘会</view>
		</block>
		<block v-if="identity==1&&tabActive==3">
			<template v-if="trainList.length>0">
				<view class="block list-block">
					<view class="item-block" v-for="(item) in trainList" :key="item.id"
						@click="navigate('/page_other/train/detail?id='+item.id+'&type='+item.trainState)">
						<view class="top-title">
							<view class="apply-title">{{item.company}}</view>
						</view>
						<view class="desc-block">
							<view class="desc">
								<view class="desc-icon iconfont icon-dianhua"></view>
								<view class="desc-text" v-if="item.mobile"><text class="label">电话：</text>{{item.mobile}}
								</view>
								<view class="desc-text" v-else><text class="label">电话：</text>暂无</view>
							</view>
							<view class="desc">
								<image :src="cloudStorage+'/train/addr_icon.png'" mode="widthFix" class="desc-icon">
								</image>
								<view class="desc-text"><text class="label">地址：</text>{{item.transaddress}}</view>
							</view>
						</view>
					</view>
				</view>
			</template>
			<view v-else-if="trainList.length>0&&!more" style="text-align: center;">到底了</view>
			<view v-else style="text-align: center;">暂未匹配到相关培训</view>
		</block>
		<Tabbar style="position: fixed; left: 0; bottom: 0;z-index:999;"></Tabbar>
	</view>
</template>

<script>
	import {
		getCustomerListApi,
		getJobRecommendation,
		jobFairRecommendation,
		trainRecommendation
	} from '@/api/job_hunting.js';
	import CustomerList from "@/components/CustomerList.vue";
	import {
		isMore
	} from '@/util/util.js';
	import {
		getUser
	} from '@/api/user.js'
	export default {
		components: {
			CustomerList
		},
		data() {
			return {
				pageType: '',
				list: [],
				page: 1,
				limit: 10,
				more: true,
				total: 0,
				showLoading: false,
				latitude: 0,
				longitude: 0,
				tabActive: 1,
				FairList: [],
				trainList: [],
				com: {
					isPublish: 1
				}
			}
		},

		methods: {
			navigate(url) {
				uni.navigateTo({
					url
				})
			},
			goCircle() {
				uni.redirectTo({
					url: '/page_other/circle/index'
				})
			},
			goView(id) {
				uni.navigateTo({
					url: '/page_other/resume/index?type=view&id=' + id
				})
			},
			bindActive(index) {
				this.tabActive = index
				this.page = 1
				if (index == 1) {
					this.getList(true)
				}
				if (index == 2) {
					this.getFairList(true)
				}
				if (index == 3) {
					this.getTrainList(true)
				}
			},
			async getList(refresh = false) {
				//if (this.more) {
				uni.showLoading({
					title: '匹配中',
					mask: true
				})
				this.latitude = uni.getStorageSync('latitude')
				this.longitude = uni.getStorageSync('longitude')
				let config = {
					page: this.page,
					limit: this.limit,
					latitude: this.latitude,
					longitude: this.longitude,
					orderDate: 0
				}
				this.showLoading = true
				let res = this.$store.getters.identity == 1 ? await getJobRecommendation(config) :
					await getCustomerListApi(config);
				if (this.$store.getters.identity == 1) {
					if (!res) {
						uni.showModal({
							title: '提示',
							content: `为了更好的为您精准的匹配岗位，请您填写您的求职意向`,
							confirmColor: '#0256FF',
							success: (res) => {
								if (res.confirm) {
									uni.reLaunch({
										url: '/page_other/resume/career_intention'
									})
								}
							}
						})
					}
				}
				this.showLoading = false;
				let list = res.list ?? [];
				this.list = refresh ? list : [...this.list, ...list]
				if (this.list.length > 0 && this.page == 1 && this.tabActive == 1) {
					this.showToast("系统已为您匹配到合适的" + this.pageType);
				};
				this.total = res.count
				this.more = isMore(this.page, this.limit, this.total)
				//}
			},
			getFairList(refresh = false) {
				this.showLoading = true
				jobFairRecommendation({
					page: this.page,
					limit: this.limit,
				}).then((res) => {
					this.showLoading = false;
					let list = res.list ?? [];
					this.FairList = refresh ? list : [...this.FairList, ...list];
					if (this.FairList.length > 0 && this.page == 1 && this.tabActive == 2) {
						this.showToast("系统已为您匹配到合适的招聘会");
					};
					this.total = res.count
					this.more = isMore(this.page, this.limit, this.total);
				})
			},
			getTrainList(refresh = false) {
				uni.showLoading({
					title: '匹配中',
					mask: true
				})
				trainRecommendation({
					page: this.page,
					limit: this.limit,
				}).then((res) => {
					uni.hideLoading()
					let list = res.modelList ?? [];
					this.trainList = refresh ? list : [...this.trainList, ...list];
					if (this.trainList.length > 0 && this.page == 1 && this.tabActive == 3) {
						this.showToast("系统已为您匹配到合适的培训");
					};
					this.total = res.count
					this.more = isMore(this.page, this.limit, this.total);
				})
			},
			getComInfo() {
				getUser({
					type: 2
				}).then((res) => {
					this.com = res
					if (this.com.isPublish == 2) {
						uni.showModal({
							title: '提示',
							content: '请先发布岗位！',
							cancelText: '先逛逛',
							confirmText: '去发布',
							success(res) {
								if (res.confirm) {
									uni.navigateTo({
										url: '/page_other/position/position_manage'
									})
								} else {
									uni.navigateTo({
										url: '/pages/home/index'
									})
								}
							}
						})
					} else {
						this.getList(true);
					}
				})
			}
		},
		computed: {
			identity() {
				return this.$store.getters.identity
			},
			user() {
				return this.$store.getters.user
			}
		},
		onShow() {
			this.pageType = this.identity == 1 ? '职位' : '求职者';

			if (this.identity == 2) {
				if (!this.user) {
					uni.showModal({
						title: '提示',
						content: '需要先登录！',
						cancelText: '先逛逛',
						confirmText: '去登录',
						success(res) {
							if (res.confirm) {
								uni.navigateTo({
									url: '/page_other/login/select'
								})
							} else {
								uni.navigateTo({
									url: '/pages/home/index'
								})
							}
						}
					})
				} else {
					this.getComInfo()
				}
			} else {
				this.getList(true);
			}
		},
		refresh() {
			this.page = 1
			this.more = true
			if (this.tabActive == 1) {
				this.getList(true);
			}
			if (this.tabActive == 2) {
				this.getFairList(true)
			}
			if (this.tabActive == 3) {
				this.getTrainList(true)
			}
		},
		onPullDownRefresh() {
			this.refresh();
			uni.stopPullDownRefresh();
		},
		onReachBottom() {
			if (this.more) {
				this.page++;
				if (this.tabActive == 1) {
					this.getList();
				}
				if (this.tabActive == 2) {
					this.getFairList()
				}
				if (this.tabActive == 3) {
					this.getTrainList()
				}
			}
		},
	}
</script>

<style lang="scss">
	$box-shadow: 0 0 10px 0 #efefef;

	page {
		background: #FAFAFA;
	}

	.content {
		width: 100%;
		overflow: hidden;
		padding-bottom: 210rpx;

		.block {
			width: 100%;
			padding: 20rpx 30rpx;
			margin-bottom: 20rpx;
			position: relative;
		}

		.block.classify-tab-block {
			width: 100%;
			height: 100rpx;
			background-color: #fff;
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: space-between;

			.tab-content {
				display: flex;
				flex-direction: row;
				justify-content: left;

				.tab-item {
					padding: 10rpx 30rpx;
					font-weight: bold;
					font-size: 36rpx;
					margin-right: 20rpx;
					flex: none;
				}

				.tab-item.active {
					color: #0256FF;
				}
			}

			.publish-btn {
				width: 45rpx;
			}

			.iconfont {
				font-size: 32rpx;
				font-weight: bold;
				color: #000;
			}
		}

		.block.label-block {
			width: 100%;
			display: flex;
			flex-direction: row;
			justify-content: left;
			align-items: center;

			.label-content {
				width: calc(100% - 110rpx);
				display: flex;
				flex-direction: row;
				justify-content: left;
				align-items: center;

				.label-item {
					padding: 10rpx 30rpx;
					font-size: 28rpx;
					color: #999;
					background: #F3F3F3;
					margin-right: 20rpx;
				}

				.label-item.active {
					color: #0256FF;
					background: #E4EFFF;
				}

			}

			.font-text {
				font-size: 28rpx;
			}

			.iconfont {
				font-size: 38rpx;
				font-weight: bold;
				margin-right: 10rpx;
			}
		}

		.block.list-block {
			box-shadow: none;
			display: flex;
			flex-direction: column;
			margin-bottom: 0;

			.list-item {
				width: 100%;
				background: #fff;
				border-radius: 10rpx;
				box-shadow: $box-shadow;
				padding: 20rpx;
				flex-direction: row;
				justify-content: center;
				margin-bottom: 20rpx;

				.detail-info {
					width: 200rpx;
					height: 200rpx;
					display: flex;
					flex-direction: row;
					flex-wrap: wrap;
					justify-content: center;
					align-items: center;

					.name {
						width: 110rpx;
						font-size: 24rpx;
						color: #999;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
						text-align: center;
						text-indent: 20rpx;
					}

					.photo {
						width: 70rpx;
						height: 70rpx;
						border-radius: 100%;
						background: #efefef;
					}

					.apply-btn {
						border: 1px solid #0256FF;
						border-radius: 8rpx;
						color: #0256FF;
						font-size: 24rpx;
						padding: 8rpx 28rpx;
						position: relative;
						left: 30rpx;
					}

					.distance {
						color: #999;
						font-size: 24rpx;

					}
				}

				.com-item {
					border-top: 1px solid #f3ebeb;
					display: flex;
					padding-top: 20rpx;

					.photo {
						width: 50rpx;
						height: 50rpx;
						border-radius: 100%;
						background: #efefef;
					}

					.distance {
						color: #999;
						font-size: 24rpx;
						margin-left: 20rpx;
					}
				}

				.list-info {
					width: calc(100% - 180rpx);
					display: flex;
					flex-direction: column;

					.title-info {
						display: flex;
						flex-direction: row;
						align-items: center;

						.title {
							color: #000;
							font-weight: bold;
							font-size: 34rpx;
						}

						.fast-job {
							width: 60rpx;
							height: 38rpx;
							border: 1rpx solid #0256FF;
							font-size: 24rpx;
							display: flex;
							align-items: center;
							justify-content: center;
							color: #0256FF;
							margin-left: 20rpx;
							border-radius: 6rpx;
						}
					}

					view {

						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}



					.address {
						color: #999;
						font-size: 26rpx;
						margin-top: 5rpx;
					}

					.label-block {
						font-size: 24rpx;
						display: flex;
						flex-direction: row;
						flex-wrap: wrap;
						justify-content: left;
						margin-top: 20rpx;

						.label-item {
							padding: 8rpx 20rpx;
							background: #F5F6F8;
							color: #999;
							margin: 0 10rpx 20rpx 0;
						}
					}

					.wage {
						color: #0256FF;
						font-size: 36rpx;
						font-weight: bold;
						padding-top: 30rpx;

						.unit {
							font-size: 28rpx;
							font-weight: normal;
						}
					}
				}
			}

			.list-item:last-child {
				margin-bottom: 0;
			}

			.model {
				width: 100%;
				height: 100%;
				border-radius: 20rpx;
				background: #fff;
				flex-direction: row;
				margin-bottom: 30rpx;
				border-bottom: 1px solid #efefef;
				position: relative;

				.ranking-block {
					display: flex;
					padding: 6rpx 0 0 16rpx;
					color: #fff;
					position: absolute;
					font-size: 28rpx;
					top: 0;
					left: -2px;
					width: 160rpx;
					height: 60rpx;
					background: url('https://job-1306862033.cos.ap-chengdu.myqcloud.com/miniprogram-static/job_hunting/job_fair/ongoing.png') no-repeat center;
					background-size: 100% 100%;
					line-height: 50rpx;
					padding-left: 36rpx;
				}

				.ranking {
					position: absolute;
					width: 160rpx;
					height: 60rpx;
					background: url('https://www.mashangjiuye.com/api/file/91885/zphing.png') no-repeat center;
					background-size: 100% 100%;
					line-hseight: 50rpx;
					padding-left: 36rpx;
				}

				.ranking-blockgrey {
					display: flex;
					padding: 6rpx 0 0 16rpx;
					color: #fff;
					position: absolute;
					font-size: 28rpx;
					top: 0;
					left: -2px;
					width: 160rpx;
					height: 60rpx;
					background: url('https://job-1306862033.cos.ap-chengdu.myqcloud.com/miniprogram-static/job_hunting/job_fair/end.png') no-repeat center;
					background-size: 100% 100%;
					line-height: 50rpx;
					padding-left: 36rpx;
				}

				.list-item {
					border-bottom: 1px solid #efefef;
					display: flex;

					.cover-photo {
						width: 140px;
						height: 80px;
						background: #efefef;
						margin-right: 20rpx;

					}

					.info {
						width: calc(100% - 195rpx);
						display: flex;
						flex-direction: column;

						.title {
							width: 100%;
							display: -webkit-box;
							-webkit-box-orient: vertical;
							-webkit-line-clamp: 2;
							overflow: hidden;
							font-weight: bold;
							font-size: 30rpx;
							color: #313131;
						}

						.host,
						.time {
							width: 100%;
							font-size: 26rpx;
							color: #999;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
						}

						.time {
							margin-top: 10rpx;
						}

						.host {
							margin-top: 10rpx;
						}

						.incount {
							display: flex;
							color: #909090;
							font-size: 28rpx;
							margin-top: 50rpx;

							.module {
								width: 130rpx;
								font-size: 24rpx;
							}

						}
					}
				}

				.lower {
					display: flex;
					margin-top: 10rpx;

					.time {
						color: #909090;
						font-size: 24rpx;
						margin-top: 15rpx;
					}

					.btn {
						width: 180rpx;
						height: 60rpx;
						line-height: 58rpx;
						border-radius: 15rpx;
						text-align: center;
						color: #fff;
						background-color: #0256FF;
						font-size: 28rpx;
						margin-left: 20px;
					}
				}

			}

			.item-block {
				width: 100%;
				height: 280rpx;
				background-color: #fff;
				box-shadow: 0px 0px 4px #ccc;
				border-radius: 10rpx;
				margin: 10rpx auto 10rpx auto;
				padding: 25rpx;

				.top-title {
					width: 100%;
					display: flex;
					align-items: center;
					justify-content: space-between;
					border-bottom: 1px solid #f6f6f6;
					padding-bottom: 25rpx;

					.apply-title {
						font-weight: bold;
						width: calc(100% - 20rpx);
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}

					.btn {
						width: 160rpx;
						height: 55rpx;
						line-height: 55rpx;
						border-radius: 50rpx;
						text-align: center;
						color: #fff;
						background-color: #0256FF;
						font-size: 28rpx;
					}
				}

				.desc-block {
					display: flex;
					flex-direction: column;

					.desc {
						display: flex;
						align-items: center;
						margin: 20rpx 0 0rpx 0;

						.iconfont {
							color: #0256FF;
							margin-right: 12rpx;
							font-weight: bold;
							padding-top: 4rpx;
						}

						.desc-icon {
							width: 30rpx;
							margin-right: 12rpx;
						}

						.desc-text {
							font-size: 30rpx;

							.label {
								color: #999;
							}
						}
					}
				}
			}
		}
	}
</style>